<html>
<head><meta charset="utf-8"><title>Slides for talk on unsafe rust · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html">Slides for talk on unsafe rust</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="165259663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165259663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165259663">(May 09 2019 at 14:53)</a>:</h4>
<p>I wrote some slides, all comments welcome</p>



<a name="165259690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165259690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165259690">(May 09 2019 at 14:53)</a>:</h4>
<p><a href="https://docs.google.com/presentation/d/1m_HxkTXWsUpX0mYGpP07eHRAzbbl-o6WQgUkb7gF-oA" target="_blank" title="https://docs.google.com/presentation/d/1m_HxkTXWsUpX0mYGpP07eHRAzbbl-o6WQgUkb7gF-oA">https://docs.google.com/presentation/d/1m_HxkTXWsUpX0mYGpP07eHRAzbbl-o6WQgUkb7gF-oA</a></p>



<a name="165259755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165259755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165259755">(May 09 2019 at 14:54)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> in particular, is the diagram on slide 13 horribly inaccurate?</p>



<a name="165259866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165259866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165259866">(May 09 2019 at 14:54)</a>:</h4>
<p>(I'm trying to summarize stacked borrows in one slide, which is tricky.)</p>



<a name="165260099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165260099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165260099">(May 09 2019 at 14:57)</a>:</h4>
<p>Also, are there other topics I should add to the laundry list on slide 15?</p>



<a name="165261119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165261119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165261119">(May 09 2019 at 15:07)</a>:</h4>
<p>oh dear, the contextual definition of unsafety^^ fun stuff</p>



<a name="165261206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165261206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165261206">(May 09 2019 at 15:08)</a>:</h4>
<p>(there might have been other ways to break josephine with an otherwise-safe abstraction pre-1.20, but that doesnt change the point you are making so whatever)</p>



<a name="165261345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165261345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165261345">(May 09 2019 at 15:09)</a>:</h4>
<p>re: Stacked Borrows, the "shared"/"unique" labels are not really on the edges from the ptr to the stack... those would be just IDs. the stack then does 2 things, it orders the ID and it says which of them are Unique, SharedReadOnly, SharedReadWrite</p>



<a name="165261526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165261526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165261526">(May 09 2019 at 15:11)</a>:</h4>
<blockquote>
<p>Also, are there other topics I should add to the laundry list on slide 15?</p>
</blockquote>
<p>not sure how specific you want to get. "developing a language spec"? "figuring out how our semantics relate to LLVM's"?</p>



<a name="165262110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262110">(May 09 2019 at 15:18)</a>:</h4>
<p>There's an argument that Josephine got broken by <code>may_dangle</code>, but you have to spec-lawyer the <code>may_dangle</code> requirements, but this sort of complicates the presentation, which is making the point "yes, this can happen in the wild".</p>



<a name="165262167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262167">(May 09 2019 at 15:18)</a>:</h4>
<p>I was pleasantly surprised to discover that the contextual defn is no longer in the rustonomicon / lang spec, the wording now is vaguer.</p>



<a name="165262168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262168">(May 09 2019 at 15:18)</a>:</h4>
<p>I was thinking of a lib that implements <code>ManuallyDrop</code> by transmuting stuff to byte arrays. IIRC someone pointed to a lib that actually does this for FFI or so...</p>



<a name="165262199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262199">(May 09 2019 at 15:19)</a>:</h4>
<p>True, but that's not in std.</p>



<a name="165262211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262211">(May 09 2019 at 15:19)</a>:</h4>
<p><code>ManuallyDrop</code> is the better-to-understand example anyway</p>



<a name="165262220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262220">(May 09 2019 at 15:19)</a>:</h4>
<p>indeed</p>



<a name="165262244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262244">(May 09 2019 at 15:19)</a>:</h4>
<p>well, having this conflict between 2 user libs makes it even more "fun" in some way</p>



<a name="165262313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262313">(May 09 2019 at 15:20)</a>:</h4>
<p>OK, I'm interested in your comment re the diagram trying to explain stacked borrows...</p>



<a name="165262355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262355">(May 09 2019 at 15:20)</a>:</h4>
<p>if the conflict is with libstd, then I guess per default libstd "wins" -- at least if the change was vetted by the lang team. but when it's two user libs, uh, we can roll a dice to decide?^^</p>



<a name="165262392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262392">(May 09 2019 at 15:21)</a>:</h4>
<p>I originally had the tags in the pointer nodes rather than on the edges</p>



<a name="165262411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262411">(May 09 2019 at 15:21)</a>:</h4>
<p>which is how it's explained in the blog post,</p>



<a name="165262423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262423">(May 09 2019 at 15:21)</a>:</h4>
<p>but isn't it equivalent to have the tags on the edges?</p>



<a name="165262576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262576">(May 09 2019 at 15:23)</a>:</h4>
<p>which blog post? things changed a bit with <a href="https://www.ralfj.de/blog/2019/04/30/stacked-borrows-2.html" target="_blank" title="https://www.ralfj.de/blog/2019/04/30/stacked-borrows-2.html">https://www.ralfj.de/blog/2019/04/30/stacked-borrows-2.html</a></p>



<a name="165262658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262658">(May 09 2019 at 15:24)</a>:</h4>
<p>I was thinking of stacked-borrows-2.</p>



<a name="165262722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262722">(May 09 2019 at 15:25)</a>:</h4>
<p>the "tags" there are just IDs</p>



<a name="165262726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262726">(May 09 2019 at 15:25)</a>:</h4>
<p>no Unique/Shared</p>



<a name="165262846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262846">(May 09 2019 at 15:26)</a>:</h4>
<p>this unique/shared/raw looks a lot like stacked borrows 1</p>



<a name="165262852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262852">(May 09 2019 at 15:26)</a>:</h4>
<p>oh I guess I had v1 and v2 mixed up in my head.</p>



<a name="165262874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262874">(May 09 2019 at 15:26)</a>:</h4>
<p>does miri implement v1 or v2?</p>



<a name="165262908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262908">(May 09 2019 at 15:27)</a>:</h4>
<p>nowadays? v2</p>



<a name="165262914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262914">(May 09 2019 at 15:27)</a>:</h4>
<p>the error msg you copied is from v2</p>



<a name="165262924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165262924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165262924">(May 09 2019 at 15:27)</a>:</h4>
<p>OK, so I should line up with v2 then.</p>



<a name="165263049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165263049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165263049">(May 09 2019 at 15:28)</a>:</h4>
<p>In v2 there's no longer metadata in the pointers, just the memory locations, yes?</p>



<a name="165263248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165263248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165263248">(May 09 2019 at 15:30)</a>:</h4>
<p>well, the metadata is the ID</p>



<a name="165263269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165263269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165263269">(May 09 2019 at 15:31)</a>:</h4>
<p>so there's still pointer provenance</p>



<a name="165263290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165263290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165263290">(May 09 2019 at 15:31)</a>:</h4>
<p>but the per-ptr-metadata no longer says "unique" or "shared" or so. it just says "18" or "25" or "&lt;untagged&gt;".</p>



<a name="165263381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165263381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165263381">(May 09 2019 at 15:32)</a>:</h4>
<p>Is SharedRW just used for interior mutability?</p>



<a name="165263439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165263439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165263439">(May 09 2019 at 15:33)</a>:</h4>
<p>no, also for <code>*mut</code></p>



<a name="165263529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165263529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165263529">(May 09 2019 at 15:34)</a>:</h4>
<p>*const and *mut are treated differently?</p>



<a name="165263664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165263664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165263664">(May 09 2019 at 15:36)</a>:</h4>
<p>yes :/</p>



<a name="165263674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165263674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165263674">(May 09 2019 at 15:36)</a>:</h4>
<p>they are treated differently by the borrow checker</p>



<a name="165263692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165263692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165263692">(May 09 2019 at 15:37)</a>:</h4>
<p>so as long as that is the case, I feel it also makes sense for Stacked Borrows, which is like a "dynamic extension" of the borrow checker</p>



<a name="165263706"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165263706" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165263706">(May 09 2019 at 15:37)</a>:</h4>
<p>TIL</p>



<a name="165263716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165263716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165263716">(May 09 2019 at 15:37)</a>:</h4>
<p>/me reads <a href="https://github.com/rust-lang/rust/issues/56604#issuecomment-477954315" target="_blank" title="https://github.com/rust-lang/rust/issues/56604#issuecomment-477954315">https://github.com/rust-lang/rust/issues/56604#issuecomment-477954315</a></p>



<a name="165263718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165263718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165263718">(May 09 2019 at 15:37)</a>:</h4>
<p>to be clear, the difference is only in what happens when you <em>create</em> the raw ptr (from a ref)</p>



<a name="165263722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165263722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165263722">(May 09 2019 at 15:37)</a>:</h4>
<p>after that, they behave the same</p>



<a name="165264521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165264521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165264521">(May 09 2019 at 15:47)</a>:</h4>
<p>lol I can watch you edit :P</p>



<a name="165265873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165265873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165265873">(May 09 2019 at 16:01)</a>:</h4>
<p>OK, is the current version more in line with stacked borrows v2?</p>



<a name="165266273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165266273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165266273">(May 09 2019 at 16:06)</a>:</h4>
<p>the diagram looks great! the comment below is not entirely correct though ("UB: creating a unique reference to a shared location")</p>



<a name="165266285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165266285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165266285">(May 09 2019 at 16:06)</a>:</h4>
<p>if the unique ref was created from x, all would be fine</p>



<a name="165266297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165266297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165266297">(May 09 2019 at 16:06)</a>:</h4>
<p>the issue is creating a unique ref <em>from an RO pointer</em></p>



<a name="165266303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165266303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165266303">(May 09 2019 at 16:07)</a>:</h4>
<p>(aka a ptr with an ID that just has RO permission in the stack)</p>



<a name="165266883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165266883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165266883">(May 09 2019 at 16:14)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> OK, I am now confused...</p>



<a name="165266944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165266944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165266944">(May 09 2019 at 16:15)</a>:</h4>
<p>the granting item for creating r is SharedRW isn't it?</p>



<a name="165267132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165267132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165267132">(May 09 2019 at 16:17)</a>:</h4>
<p>no. your <code>SharedRW</code> is wrong. (I had missed that.)</p>



<a name="165267135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165267135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165267135">(May 09 2019 at 16:17)</a>:</h4>
<p>raw-to-raw-casts do nothing</p>



<a name="165267141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165267141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165267141">(May 09 2019 at 16:17)</a>:</h4>
<p>the interesting action is your <code>&amp;T</code>-to-<code>*const T</code> when <code>q</code> gets created.</p>



<a name="165267150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165267150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165267150">(May 09 2019 at 16:17)</a>:</h4>
<p>that adds a <code>SharedRO(&lt;untagged&gt;)</code></p>



<a name="165267385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165267385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165267385">(May 09 2019 at 16:20)</a>:</h4>
<p>Ah, in (p as *const T as *mut T) it's only the SharedRO that gets pushed on the stack, not the sharedRW?</p>



<a name="165267391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165267391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165267391">(May 09 2019 at 16:20)</a>:</h4>
<p>Showing the untagged item as just <code>SharedRW</code> is a bit misleading since this tag does not apply to all pointers -- it only applies to untagged ptrs</p>



<a name="165267405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165267405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165267405">(May 09 2019 at 16:20)</a>:</h4>
<blockquote>
<p>Ah, in (p as *const T as *mut T) it's only the SharedRO that gets pushed on the stack, not the sharedRW?</p>
</blockquote>
<p>correct. no <code>SharedRW</code> ever gets pushed in your example.</p>



<a name="165267724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165267724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165267724">(May 09 2019 at 16:24)</a>:</h4>
<p>OK, I replaced that by _: SharedRO</p>



<a name="165267767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165267767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165267767">(May 09 2019 at 16:25)</a>:</h4>
<p>since the slide no longer has any SharedRW on it, I'm tempted to s/sharedRO/shared/</p>



<a name="165267880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165267880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165267880">(May 09 2019 at 16:26)</a>:</h4>
<p>I'd still also fix the sentence at the bottom</p>



<a name="165267905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165267905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165267905">(May 09 2019 at 16:27)</a>:</h4>
<p>the issue with <code>r</code> is not the location, its the pointer it comes from</p>



<a name="165268267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165268267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165268267">(May 09 2019 at 16:31)</a>:</h4>
<p>Oh I see, so when doing <code>q.as_mut()</code> we are looking for a granting item with tag <code>_: Unique</code> or <code>_: SharedRW</code> and there is none.</p>



<a name="165268635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165268635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165268635">(May 09 2019 at 16:36)</a>:</h4>
<p>yes. (and it's <code>_</code> because that's <code>q</code>'s tag)</p>



<a name="165268666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165268666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165268666">(May 09 2019 at 16:37)</a>:</h4>
<p>that's not "requires a  _: unique" though</p>



<a name="165268701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165268701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165268701">(May 09 2019 at 16:37)</a>:</h4>
<p>if you dont want to mention <code>SharedRW</code>, maybe state the negative? "UB: Creating a unique reference from a <code>SharedRO</code>-pointer"</p>



<a name="165268785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165268785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165268785">(May 09 2019 at 16:38)</a>:</h4>
<p>hmm, I guess I elided too much by getting rid of sharedRW.</p>



<a name="165270499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165270499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165270499">(May 09 2019 at 17:00)</a>:</h4>
<p>BTW, while I was writing the slides, I was wondering if there's a model where we consider pointers to have Drop code that has no effect on the state, but updates the shadow state? Then all the "removing entries from the stack" would be done by drop, not by accesses.</p>



<a name="165270591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165270591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165270591">(May 09 2019 at 17:01)</a>:</h4>
<p>This model would have more UB, as it would depend on when the compiler inserts drops for pointers, which it can only do using static information .</p>



<a name="165271697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165271697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165271697">(May 09 2019 at 17:17)</a>:</h4>
<p>Oops should have tagged <span class="user-mention" data-user-id="120791">@RalfJ</span> re ^</p>



<a name="165271713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165271713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165271713">(May 09 2019 at 17:17)</a>:</h4>
<p>The venue for the talk is <a href="https://www.meetup.com/Chicago-Rust-Meetup/events/260918979/" target="_blank" title="https://www.meetup.com/Chicago-Rust-Meetup/events/260918979/">https://www.meetup.com/Chicago-Rust-Meetup/events/260918979/</a></p>



<a name="165274093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165274093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165274093">(May 09 2019 at 17:52)</a>:</h4>
<blockquote>
<p>BTW, while I was writing the slides, I was wondering if there's a model where we consider pointers to have Drop code that has no effect on the state, but updates the shadow state? Then all the "removing entries from the stack" would be done by drop, not by accesses.</p>
</blockquote>
<p>I haven't thought about this. It wouldn't really be implementable in Miri because there's no actual code saying when that "virtual drop" happens. I mean, <code>&amp;T</code> are even <code>Copy</code>, that kind of contradicts the idea of them being <code>Drop</code> as well. And then there is the question of what happens when someone <code>mem::forget</code>'s?</p>



<a name="165274121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165274121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165274121">(May 09 2019 at 17:52)</a>:</h4>
<p>also with NLL we do have ptrs that get invalidated before they would get dropped. so it dosn't seem to me like it'd be a good fit.</p>



<a name="165274126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165274126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165274126">(May 09 2019 at 17:52)</a>:</h4>
<blockquote>
<p>The venue for the talk is <a href="https://www.meetup.com/Chicago-Rust-Meetup/events/260918979/" target="_blank" title="https://www.meetup.com/Chicago-Rust-Meetup/events/260918979/">https://www.meetup.com/Chicago-Rust-Meetup/events/260918979/</a></p>
</blockquote>
<p>cool!</p>



<a name="165274134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165274134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165274134">(May 09 2019 at 17:52)</a>:</h4>
<p><span class="user-mention" data-user-id="128323">@Alan Jeffrey</span> ^</p>



<a name="165275088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165275088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165275088">(May 09 2019 at 18:04)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> yes, you'd have to introduce a type <code>&amp;immut T</code> which is like <code>&amp;T</code> but doesn't implement <code>Copy</code>, and have all <code>&amp;mut T</code> to <code>&amp;T</code> coercions go via <code>&amp;immut T</code>.</p>



<a name="165275116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165275116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165275116">(May 09 2019 at 18:05)</a>:</h4>
<p>That way <code>&amp;immut T</code> could have drop code.</p>



<a name="165275146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165275146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165275146">(May 09 2019 at 18:05)</a>:</h4>
<p>And grr, <code>mem::forget</code>, grr.</p>



<a name="165275348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165275348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165275348">(May 09 2019 at 18:08)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> yes, you'd have to introduce a type <code>&amp;immut T</code> which is like <code>&amp;T</code> but doesn't implement <code>Copy</code>, and have all <code>&amp;mut T</code> to <code>&amp;T</code> coercions go via <code>&amp;immut T</code>.</p>
</blockquote>
<p>I dont think that'd be enough; we still also have to do retagging for regulat <code>&amp;T</code> to be sure we really have a pointer with the right permissions</p>



<a name="165282875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165282875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165282875">(May 09 2019 at 19:43)</a>:</h4>
<p>I wrote a very rough first draft implementation at <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=79c808e6d9d84a4176083b517d1680db" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=79c808e6d9d84a4176083b517d1680db">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=79c808e6d9d84a4176083b517d1680db</a></p>



<a name="165283075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165283075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165283075">(May 09 2019 at 19:46)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> no interior mutability, checks for use-after-free etc. But it does have the idea of using drop code to update shadow state on <code>&amp;immut T</code>. The shadow state is very simple, just one bit!</p>



<a name="165283157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165283157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165283157">(May 09 2019 at 19:47)</a>:</h4>
<p>My first attempt in 2017, "Types as Contracts", relied on <code>EndLifetime</code> -- knowing in the code when a lifetime ended. I kind of abandoned that idea after my experience there.  But this is somehow different, it per-reference, not per-lifetime.</p>



<a name="165283498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165283498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165283498">(May 09 2019 at 19:52)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> yes, this is sort of like using explicit markers for lifetimes, but using them to explicitly freeze / thaw a mutable reference.</p>



<a name="165283582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165283582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165283582">(May 09 2019 at 19:53)</a>:</h4>
<p>Of course really you'd want each byte to have its own shadow state, not just each object.</p>



<a name="165314965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165314965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165314965">(May 10 2019 at 07:11)</a>:</h4>
<p>still, to support NLL this pretty much requires the borrow checker to mark in the code where lifetimes end. And with pollonius, not even the borrow checker knows.</p>



<a name="165346354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165346354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165346354">(May 10 2019 at 15:38)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span>  Since the lifetime ends are just used to update the shadow state, can the spec just give the compiler the freedom to add them wherever it likes? This doesn't help miri though :/</p>



<a name="165350787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165350787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165350787">(May 10 2019 at 16:35)</a>:</h4>
<p>that also sounds rather inconvenient when you try to argue that your unsafe code is correct -- which crucially depends on the shadow state</p>



<a name="165350848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165350848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165350848">(May 10 2019 at 16:36)</a>:</h4>
<p>I dont think the compiler should have the freedom to insert code whereever it likes if that code can cause UB^^</p>



<a name="165487782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165487782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165487782">(May 13 2019 at 00:09)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> True, but it's the same annoyance as reasoning about any program with drop code.</p>



<a name="165487785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165487785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165487785">(May 13 2019 at 00:09)</a>:</h4>
<p>I wrote a cleaner version of this at <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=90773fba2b71073841015190bc8c1fdb" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=90773fba2b71073841015190bc8c1fdb">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=90773fba2b71073841015190bc8c1fdb</a></p>



<a name="165517881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165517881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165517881">(May 13 2019 at 11:07)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> True, but it's the same annoyance as reasoning about any program with drop code.</p>
</blockquote>
<p><span class="user-mention" data-user-id="128323">@Alan Jeffrey</span>  not really... the other drop code is real, and when we are working on the MIR it is explicit. that is one reason why I like to work on the MIR level.</p>



<a name="165518007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165518007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165518007">(May 13 2019 at 11:09)</a>:</h4>
<p>Also, I think there is not enough information here to handle interior mutability -- in particular, code like this where <code>&amp;</code> and <code>&amp;mut</code> alias and both can be reborrowed:</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">aliasing_mut_and_shr</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">inner</span><span class="p">(</span><span class="n">rc</span>: <span class="kp">&amp;</span><span class="nc">RefCell</span><span class="o">&lt;</span><span class="kt">i32</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">aliasing</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="o">*</span><span class="n">aliasing</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">4</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">_escape_to_raw</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">rc</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="n">_</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="o">*</span><span class="n">aliasing</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">4</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">_shr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;*</span><span class="n">rc</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="o">*</span><span class="n">aliasing</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">4</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="c1">// also turning this into a frozen ref now must work</span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">aliasing</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;*</span><span class="n">aliasing</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">_val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">*</span><span class="n">aliasing</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">_escape_to_raw</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">rc</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="n">_</span><span class="p">;</span><span class="w"> </span><span class="c1">// this must NOT unfreeze</span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">_val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">*</span><span class="n">aliasing</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">_shr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;*</span><span class="n">rc</span><span class="p">;</span><span class="w"> </span><span class="c1">// this must NOT unfreeze</span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">_val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">*</span><span class="n">aliasing</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">rc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">RefCell</span>::<span class="n">new</span><span class="p">(</span><span class="mi">23</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">bmut</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">rc</span><span class="p">.</span><span class="n">borrow_mut</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">inner</span><span class="p">(</span><span class="o">&amp;</span><span class="n">rc</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="o">*</span><span class="n">bmut</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">drop</span><span class="p">(</span><span class="n">bmut</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">assert_eq</span><span class="o">!</span><span class="p">(</span><span class="o">*</span><span class="n">rc</span><span class="p">.</span><span class="n">borrow</span><span class="p">(),</span><span class="w"> </span><span class="mi">23</span><span class="o">+</span><span class="mi">12</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="165536193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/165536193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#165536193">(May 13 2019 at 14:58)</a>:</h4>
<p>I think we should move this to a new topic...</p>



<a name="166912080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/166912080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#166912080">(May 30 2019 at 14:25)</a>:</h4>
<p>I gave the talk, it seemed to go well.</p>



<a name="166912931"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/166912931" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#166912931">(May 30 2019 at 14:35)</a>:</h4>
<p>awesome :)</p>



<a name="166913326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/166913326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#166913326">(May 30 2019 at 14:39)</a>:</h4>
<p>The talk was recorded, though there may have been issues with the audio, so we shall see if its usable. I hope I didn't say anything too controversial!</p>



<a name="166913422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides%20for%20talk%20on%20unsafe%20rust/near/166913422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alan Jeffrey <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Slides.20for.20talk.20on.20unsafe.20rust.html#166913422">(May 30 2019 at 14:40)</a>:</h4>
<p>I did get a comment afterwards of "boy you don't like C APIs", which is probably true.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>